<template>
  <div>
    <el-table :data="schedulelist" stripe style="width: 100%">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="hash.ep_ename" label="仪器设备名称" width="250"></el-table-column>
      <el-table-column prop="hash.scale" label="规格型号" width="150"></el-table-column>
      <el-table-column prop="hash.managenum" label="管理编号" width="150"></el-table-column>
      <el-table-column prop="hash.traceability" label="溯源方式"></el-table-column>
      <el-table-column prop="hash.verifiy_company" label="检定/校准单位" width="250"></el-table-column>
      <el-table-column prop="hash.verifiy_person" label="检定员"></el-table-column>
      <el-table-column prop="hash.realtime" label="实际检定/校准时间" width="100"></el-table-column>
      <el-table-column prop="hash.verifiy_round" label="检定/校准周期"></el-table-column>
      <el-table-column prop="hash.verifiytime" label="计划检定/校准日期" width="100"></el-table-column>
      <el-table-column prop="hash.realtime" label="实际检定/校准时间" width="100"></el-table-column>
      <el-table-column prop="hash.nextverifiytime" label="下次检定/校准日期" width="100"></el-table-column>
      <el-table-column label="检定状态" width="150">
        <template slot-scope="scope">
          <span v-if="scope.row.hash.status=='0'">未提交证书</span>
          <span v-else-if="scope.row.hash.status=='1'">已提交证书</span>
          <span v-else>无需确认</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="350">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" @click="showdia(1,scope.row)" v-if="usertype==1&&scope.row.hash.status=='0'">提交检定</el-button>
          <el-button size="mini" type="primary" @click="showdia(0,scope.row.hash.id)" v-if="usertype==1&&scope.row.hash.status=='1'">确认记录</el-button>
          <el-button size="mini" type="primary" @click="showsubcheck(scope.row)" v-if="usertype==1&&scope.row.hash.status=='1'">检定报告</el-button>
          <el-button size="mini" type="primary" @click="showsubcost(scope.row)" v-if="usertype==1&&scope.row.hash.status=='1'">修改检定费用</el-button>

        </template>
      </el-table-column>
    </el-table>

    <div v-if="schedulelist.length>0">
      <submitcheck v-if="step1" :item1="item1"></submitcheck>
      <submitrecord v-if="step0" :approvetable="approvetable0"></submitrecord>
    </div>

    <!-- //设备检定管理员模块 -->
    <el-dialog
      title="查看检定报告"
      :visible.sync="showcheckreport"
      width="50%"
      appendToBody
    >
      <p>检定/校准费用： {{verifiy_fee}}</p>
      <el-table
        :data="checkreportlist"
        stripe
        style="width: 100%"
      >
        <el-table-column
          type="index"
          width="50"
        >
        </el-table-column>
        <el-table-column
          prop="hash.certnum"
          label="证书编号"
        >
        </el-table-column>
        <el-table-column label="查看附件">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" @click="checkfj(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
        title="查看附件"
        :visible.sync="showcheckreport2"
        appendToBody
      >
        <el-table
          :data="fileArr"
          stripe
          style="width: 100%"
        >
          <el-table-column
            type="index"
            width="50"
          >
          </el-table-column>
          <el-table-column
            prop="hash.filename"
            label="附件名称"
          >
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <a :href="scope.row.hash.fileurl" target="_blank" download="">下 载</a>
            </template>
          </el-table-column>
        </el-table>
      </el-dialog>
    </el-dialog>
    <el-dialog title="修改检定费用" width="30%" :visible.sync="showcheckreport3" appendToBody>
      <el-form labelWidth="60px">
        <el-form-item label="金额">
          <el-input v-model="check_fee"></el-input>
        </el-form-item>
      </el-form>
      <div class="foot">
        <el-button type="primary" size="mini" @click="showsubcostsure">确定</el-button>
        <el-button size="mini" @click="showsubcostcancle">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import submitcheck from '~/components/apparatus/eqschedule/submitcheck.vue';
import submitrecord from '~/components/apparatus/eqschedule/submitrecord.vue';

export default {
  components: {
    submitcheck,
    submitrecord,
  },
  data() {
    return {
      ts: this.newStore(),
      showcheckreport: false,
      showcheckreport2: false,
      showcheckreport3: false,
      dialogVisible: false,
      showcofirm: false,
      showcofirm2: false,
      showsh: false,
      showsh2: false,
      step0: false,
      step1: false,
      step2: false,
      step3: false,
      step4: false,
      item1: {},
      item2: {},
      item3: {},
      verifiy_fee: '',
      check_fee: '',
      checkreportlist: [],
      fileArr: [],
      fileArr2: [],
      cofirmtable: [],
      shtable: [],
      approvetable: [],
      approvetable0: [],
    };
  },
  props: {
    schedulelist: {
      type: Array,
      required: true,
    },
    usertype: {
      type: Number,
      required: true,
    },
    choosedp: Array,
  },
  methods: {
    handleCurrentChange() {
      const a = this.schedulelist[0].hash.eid;
      const req = {
        handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7A4BDCEC5DB08E43DBCD3A43E9777C4E90',
        eid: a,
        start: '0',
        limit: '100000',
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.schedulelist = ts.d.data.operation1;
      });
    },
    showconfirmrecord(item) {
      this.item2 = item;
      this.reload('step2');
    },
    checkfj(item) {
      console.log(item);
      const req = {
        handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7AF1087BC5FD3B20C51F0C438E24ECDA3C',
        id: item.hash.id,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.fileArr = ts.d.data.operation1;
        this.showcheckreport2 = true;
      });
    },
    checkfj2(item) {
      console.log(item);
      const req = {
        handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7AF1087BC5FD3B20C51F0C438E24ECDA3C',
        id: item.hash.cid,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.fileArr2 = ts.d.data.operation1;
        this.showcofirm2 = true;
      });
    },
    showsubcheck(item) {
      console.log(item);
      const req = {
        handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7AF1087BC5FD3B20C5CD3A43E9777C4E90',
        id: item.hash.id,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.verifiy_fee = ts.d.data.operation1[0].hash.verifiy_fee;
        this.checkreportlist = ts.d.data.operation2;
        this.showcheckreport = true;
      });
    },
    showsubcost(item) {
      this.showcheckreport3 = true;
      this.item3 = item;
    },
    showsubcostsure() {
      this.$confirm('确认修改？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        const req = {
          handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7A1E15E5E78DA2A3B6FD58B6E268D37EF8',
          id: this.item3.hash.id,
          verifiy_fee: this.check_fee,
        };
        this.spost(this.ts, '/mainservlet', req).then((ts) => {
          this.showcheckreport3 = false;
        });
      });
    },
    showsubcostcancle() {
      this.showcheckreport3 = false;
    },
    selectable(row) {
      if (row.hash.status == '0') {
        return true;
      }
      return false;
    },
    showdia(type, item) {
      if (type == 0) {
        const req = {
          handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7AF1087BC5FD3B20C53BF12CE79649F82DF9BE89CF91227798',
          id: item,
        };
        this.spost(this.ts, '/mainservlet', req).then((ts) => {
          this.approvetable0 = ts.d.data.operation1;
        });
        this.reload('step0');
      } else if (type == 1) {
        this.item1 = item;
        this.reload('step1');
      }
    },
    reload(vifname) {
      this[vifname] = false;
      this.$nextTick(() => {
        this[vifname] = true;
      });
    },
  },
};
</script>

<style scoped>
.foot {
  text-align: right;
}
</style>
